﻿using System;
using System.Collections.Generic;

namespace ClusterLibrary
{
    public class Map
    {
        private List<ClusterView> map;
        private List<ClusterView> neighbors;

        public List<ClusterView> Clusters
        {
            get
            {
                return this.map;
            }
        }

        public Map()
        {
            this.map = new List<ClusterView>();
            this.neighbors = new List<ClusterView>();
        }

        public void addCluster(ClusterView cluster)
        {
            this.map.Add(cluster);
        }

        public void removeCluster(ClusterView cluster)
        {
            if (!this.map.Remove(cluster))
            {
                this.neighbors.Remove(cluster);
            }
        }

        public ClusterView getCluster(int x, int y)
        {
            foreach (ClusterView cluster in this.map)
            {
                if (cluster.isActive(x, y)) return cluster;
            }
            foreach (ClusterView cluster in this.neighbors)
            {
                if (cluster.isActive(x, y)) return cluster;
            }
            return null;
        }

        public void addSubclass(int x, int y)
        {
            ClusterView focusedCluster = this.getCluster(x, y);

            if (focusedCluster != null)
            {
                focusedCluster.addSubclass();
            }
        }

        public void removeSubclass(int x, int y)
        {
            ClusterView focusedCluster = this.getCluster(x, y);
            if (focusedCluster != null)
            {
                focusedCluster.removeSubclass(focusedCluster.getSubclass(x, y));
            }
        }


        /*public void addNeighbour(Cluster cluster, Cluster neighbour)
        {
            this.neighbours[cluster].Add(neighbour);
        }

        public void removeNeighbour(Cluster cluster, Cluster neighbour)
        {
            this.neighbours[cluster].Remove(neighbour);
        }*/
    
    }
}
